package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.RankBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 作者：王加威 on 2016/11/16 11:04
 */

public class MyListViewAdapter2 extends BaseAdapter{
    private Context mContext;
    private List<RankBean.DataBean> mRankBeen;

    public MyListViewAdapter2(Context context, List<RankBean.DataBean> rankBeen) {
        mContext = context;
        mRankBeen = rankBeen;
    }

    @Override
    public int getCount() {
        return mRankBeen==null?0:mRankBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return mRankBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null) {
            convertView= LayoutInflater.from(mContext).inflate(R.layout.list_item,null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        Picasso.with(mContext).load(mRankBeen.get(position).image_url).into(viewHolder.mImageView);
        viewHolder.mTextView1.setText(mRankBeen.get(position).short_name);
        viewHolder.mTextView2.setText(mRankBeen.get(position).p_price);
        viewHolder.mButton.setText("第"+(position+1)+"名");
        return convertView;
    }
    public static class ViewHolder{
        private ImageView mImageView;
        private TextView mTextView1,mTextView2;
        private Button mButton;
        public ViewHolder(View view){
            mImageView= (ImageView) view.findViewById(R.id.list_iv);
            mTextView1= (TextView) view.findViewById(R.id.list_tv1);
            mTextView2= (TextView) view.findViewById(R.id.list_tv2);
            mButton= (Button) view.findViewById(R.id.list_bt);
            mButton.setClickable(false);
        }
    }
}
